package com.xzit.rcpyxt.service.impl;

import com.xzit.rcpyxt.dto.*;
import com.xzit.rcpyxt.entity.Student;
import com.xzit.rcpyxt.mapper.StudentMapper;
import com.xzit.rcpyxt.service.StudentService;
import com.xzit.rcpyxt.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageUtil findByTeacherList(ClassUserListRequest studentDto) {
        int page = studentDto.getPage();
        int pageSize = studentDto.getPageSize();
        studentDto.setPage(page - 1);
        studentDto.setPageSize(page * pageSize);
        List<Student> teachers = studentMapper.selectByClassStudentList(studentDto);
        int totalElements = studentMapper.countByClassStudentList(studentDto);
        return new PageUtil(page, pageSize, totalElements, teachers);
    }

    @Override
    public PageUtil findByStudentList (StudentBindRequest studentDto) {
        int page = studentDto.getPage();
        int pageSize = studentDto.getPageSize();
        studentDto.setPage(page - 1);
        studentDto.setPageSize(page * pageSize);
        List<Student> teachers = studentMapper.selectByStudentList(studentDto);
        int totalElements = studentMapper.countByStudentList(studentDto);
        return new PageUtil(page, pageSize, totalElements, teachers);
    }

}
